package www.lagou.app;

import www.lagou.entity.Account;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.sql.SQLException;

/**
 * 测试类
 */
public class MainTest {
    public static void main(String[] args) throws SQLException {
        LocalDateTime now = LocalDateTime.now();
        System.out.println("获取到的当前日期是：" + now);
//        获取tom 和 Lucy 在数据库中保存的数据
        Account tom = Transaction.getAccount("tom");
        Account lucy = Transaction.getAccount("lucy");
//        模拟 tom 向  Lucy转账
//        判断tom的账户余额是否大于转账余额
        Double tranMoney = 300.00;
        double tomBalance = tom.getBalance();
        if (tomBalance >= tranMoney){
//          实现Tom转出
            Transaction.transact(tom.getBalance()-tranMoney,tom.getCard());
//            实现Lucy转入
            Transaction.transact(lucy.getBalance()+tranMoney,lucy.getCard());
//            Tom交易记录入库
            Transaction.setTransact(tom.getCard(),"tranIn",tranMoney,LocalDateTime.now());
//            Lucy交易记录入库
            Transaction.setTransact(lucy.getCard(),"tranOut",tranMoney,LocalDateTime.now());
        }else {
            System.out.println("tom的余额小于转款余额，转款失败！");
        }


    }
}
